﻿using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Medicalsystem.MCP.FormDesigner.Property;

namespace Medicalsystem.MCP.FormDesigner.MyControls
{
    /// <summary>
    /// MutiLabel 控件与属性编辑器交互
    /// </summary>
    public class GetMutiLabelProperty : GetCtrlUIProperty
    {
        public GetMutiLabelProperty(MutiLabel mutiLable)
            : base(mutiLable)
        {
            _mutiLable = mutiLable;
        }

        private MutiLabel _mutiLable = null;

        /// <summary>
        /// 字体位置
        /// </summary>
        [CategoryAttribute("外观")]
        [ShowChinese("字体位置")]
        [Description("字体位置")]
        [Browsable(true)]
        public ContentAlignment TextAlign
        {
            get
            {
                return _mutiLable.TextAlign;
            }
            set
            {
                this.OnSetPropertyBatch(this, "TextAlign", value);
            }
        }

        /// <summary>
        /// 背景图像
        /// </summary>
        [CategoryAttribute("外观")]
        [ShowChinese("背景图像")]
        [Description("用于该窗体的背景图像")]
        public Image BackgroundImage
        {
            get
            {
                return _mutiLable.BackgroundImage;
            }
            set
            {
                if (value != null)
                {
                    System.IO.MemoryStream ImageMem = new System.IO.MemoryStream();
                    value.Save(ImageMem, value.RawFormat);

                    if (ImageMem.Length > 524288)
                    {
                        MessageBox.Show("请选择小于512KB的图片资源", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        _mutiLable.BackgroundImage = value;
                    }
                }
                else
                {
                    _mutiLable.BackgroundImage = value;
                }
            }
        }

        /// <summary>
        /// 图像布局
        /// </summary>
        [CategoryAttribute("外观")]
        [ShowChinese("图像布局")]
        [Description("用于组件的背景图像布局")]
        public ImageLayout BackgroundImageLayout
        {
            get
            {
                return _mutiLable.BackgroundImageLayout;
            }
            set
            {
                _mutiLable.BackgroundImageLayout = value;
            }
        }

        /// <summary>
        /// 设置控件属性
        /// </summary>
        /// <param name="propertyName"></param>
        /// <param name="value"></param>
        public override void SetProperty(string propertyName, object value)
        {
            switch (propertyName.ToLower())
            {
                case "textalign":
                    _mutiLable.TextAlign = (ContentAlignment)value;
                    break;
                default:
                    base.SetProperty(propertyName, value);
                    break;
            }
        }
    }
}